package com.zqu.controller;

import com.zqu.pojo.User;
import com.zqu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("finduser")
    @ResponseBody
    public String selectById(){
        User user = new User();
        user.setLoginUserId(1);
        User user1 = userService.selectUser(user);
        System.out.println("=======================================");
        System.out.println(user1.toString());
        System.out.println("=======================================");

        return user1.toString();
    }

    @RequestMapping("selctlist")
    @ResponseBody
    public List<User> selectlist(){
        return userService.selectList(new User());
    }

    @RequestMapping("insertuser")
    @ResponseBody
    public boolean insert(){
        return userService.insertUser(new User(3,1,"xzk","nan",18,null,null,1,null,null));
    }

    @RequestMapping("updateuser")
    @ResponseBody
    public boolean update(){
        return userService.updateUser(new User(3,1,"xzk","nan",19,null,null,1,null,null));
    }

    @RequestMapping("deleteuser")
    @ResponseBody
    public boolean delete(){
        return userService.deleteUser(3);
    }

    @RequestMapping("deleteuserbyids")
    @ResponseBody
    public boolean deleteuserbyids(){
        String[] ids = {"1","3"};
        return userService.deleteUserByIds(ids);
    }
}
